﻿<?if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
module : vng sales marketing
author : hoanghd@vinagame.com.vn
********************************************************************************/
require_once('XTemplate/xtpl.php');
require_once('log4php/LoggerManager.php');
require_once('include/modules.php');
require_once('modules/ZT2Remit/ZT2Remit.php');

global $current_language;
global $app_strings;
global $app_list_strings;
global $theme;
$theme_path = 'themes/' . $theme . '/';
$image_path = $theme_path .'images/';
require_once($theme_path . 'layout_utils.php');
global $mod_strings;



$mode_inpvl=$_POST["mode_inpvl"];
$insert=$_GET["insert"];
$seed = new ZT2Remit_Ext();
$fnc = new FNC();


$pst_mode=$_POST["mode"];
$pst_chk=$_POST["chk"];

//print "<pre>";
//print_r($_SESSION);

// kiem tra quyen access 
if ($seed->ACLAccess('view') && $seed->ACL_Access('List')) {
	ob_start();





	$list_form = new XTemplate('modules/ZT2Remit/List.html');
	$seed->set_theme($list_form);
	$PN_Error = '';




	$search_type[0]='Tài khoản CSM cũ';
	$search_field[0]='oldZingId';
    $search_type[1]='Tài khoản Đăng ký';
	$search_field[1]='newZingId';
    $search_type[2]='Tên phòng máy';
	$search_field[2]='FullName';
    $search_type[3]='Tên chủ phòng máy';
	$search_field[3]='GameRoomName';
    $search_type[4]='Địa chỉ';
	$search_field[4]='Address';
    $search_type[5]='Số điện thoại';
	$search_field[5]='Phone';
    $search_type[6]='Email';
	$search_field[6]='Email';
    $search_type[7]='CMND';
	$search_field[7]='CMND';  
   			
    

	$_where="";
	$_vl_search_type=$_POST["search_type"];
	$_vl_keyword=$_POST["keyword"];
	$_vl_from_date=$_POST["from_date"];
    // m
	//$_vl_search_type=$_POST["search_type"];
//	$_vl_keyword=$_POST["keyword"];
//	$_vl_from_date=$_POST["from_date"];
	$_vl_to_date=$_POST["to_date"];
	$_pst_locationId_area = _get('fld_lo_105108_108111999711610511111073100_area');
	$_pst_locationId_city = _get('fld_lo_105108_108111999711610511111073100_city');	
	$_pst_locationId_district = _get('fld_lo_105108_108111999711610511111073100_district');
	//$_pst_statusId = _get('fld_1151169711611711573100');
	$locationId = $_pst_locationId_district!=''?$_pst_locationId_district:($_pst_locationId_city!=''?$seed->fnc_get_locationId($_pst_locationId_city):($_pst_locationId_area!=''?$seed->fnc_get_locationId($_pst_locationId_area):""));


    // end m


	if ($_vl_keyword!='' && $_vl_search_type!=''){
			$_where.=" and ".$search_field[$_vl_search_type]." like ''%".$seed->anti($_vl_keyword)."%'' ";
	}
	
//	$_vl_gamecode_list=$_POST["gamecode_list"];
//	if ($_vl_gamecode_list!=''){
//		$_where.=" and gamecode = ''".$seed->anti($_vl_gamecode_list)."'' ";	
//	}

	$gridview='';
    $DBList = $seed->setList($fnc,$_where,$_vl_from_date,$_vl_to_date,$locationId,$_pst_statusId,$list_form);   
    //$DBList = $seed->setList($fnc,$_where,$_vl_from_date,$list_form);	
	$gridview.= $seed->_AddPageHeader();
	$gridview.= $seed->PageHeader();
	$exportGrid = $seed->setHeader();
	$exportGrid.= $DBList[0];
	$gridview.= $exportGrid;		
	$gridview.=$seed->setFooter();
	$gridview.=$seed->setPaging();

	
	$title='Danh sách Phòng máy đăng ký';
	if($_POST['mode']=='EXPORT' && $seed->ACL_Page(1,'List'))
		{			
			$seed->ExportToExcel($seed->fnStrConvert($title),$exportGrid);							
			die();
		}







//	$arr_info_gamecode_list = $seed->fnc_get_gamecode();        
	//print_r($arr_info_gamecode_list);
//	$arr_attr_gamecode_list = array('style'=>'');
//	$sel_info_gamecode_list = $fnc->addSelectList2('gamecode_list',$arr_info_gamecode_list,'--- Tất cả ---',$arr_attr_gamecode_list,$list_form,$_gamecode_list); 




	$attr_search_type = array("style"=>'','title'=>'Tìm kiếm theo');
	$search_type = $fnc->addSelectList('search_type',$search_type,'--- Tìm kiếm theo ---',$attr_search_type,$list_form);	


	$arr_attr_keyword = array('style'=>'');
	$inp_keyword = $fnc->addInput('text','keyword',$keyword,$arr_attr_keyword,$list_form);

	$arr_attr_from_date = array('style'=>'');
	$inp_from_date = $fnc->addInput('text','from_date',$from_date,$arr_attr_from_date,$list_form);
	
    $arr_attr_from_date = array('style'=>'');
	$inp_from_date = $fnc->addInput('text','to_date',$to_date,$arr_attr_to_date,$list_form);
	
    
    // vung mien
    //area
	$arr_info_locationId_area_list = $seed->location_area(1);
	$arr_attr_locationId_area_list = array('rel1'=>'{Require:\'R\',Alert:\'Vui lòng chọn Vùng/miền \'}','style'=>'','onchange'=>'getLocation_city(\'#form1\')');
	$sel_info_locationId_area_list = $fnc->addSelectList2('fld_lo_105108_108111999711610511111073100_area',$arr_info_locationId_area_list[0],'--- Vùng/miền ---',$arr_attr_locationId_area_list,$list_form,$_pst_locationId_area);



	//city
	$arr_info_locationId_city_list = $seed->location_by_city($_pst_locationId_area);
	$arr_attr_locationId_city_list = array('rel1'=>'{Require:\'R\',Alert:\'Vui lòng chọn tỉnh/thành \'}','style'=>'','onchange'=>'getLocation_district(\'#form1\')');
	$sel_info_locationId_city_list = $fnc->addSelectList2('fld_lo_105108_108111999711610511111073100_city',$arr_info_locationId_city_list[0],'--- Tỉnh/thành ---',$arr_attr_locationId_city_list,$list_form,$_pst_locationId_city);



	//district
	$arr_info_locationId_district_list = $seed->location_by_district($_pst_locationId_city);
	$arr_attr_locationId_district_list = array('rel1'=>'{Require:\'R\',Alert:\'Vui lòng chọn Quận/huyện \'}','style'=>'');
	$sel_info_locationId_district_list = $fnc->addSelectList2('fld_lo_105108_108111999711610511111073100_district',$arr_info_locationId_district_list[0],'--- Quận/huyện ---',$arr_attr_locationId_district_list,$list_form,$_pst_locationId_district);
/*

	$arr_info_statusId_list = $seed->fnc_get_status();
	$arr_attr_statusId_list = array('rel1'=>'{Require:\'R\',Alert:\'Vui lòng ch?n Game code \'}','style'=>'');
	$sel_info_statusId_list = $fnc->addSelectList2('fld_1151169711611711573100',$arr_info_statusId_list,'--- T?t c? ---',$arr_attr_statusId_list,$list_form,$_pst_statusId);

*/
    //end vung mien
    
    
	if ($seed->ACL_Page(1,'List')){	
		$arr_attr_btnexport = array('style'=>'','onclick'=>'sbm_form(2)');
		$inp_btnexport = $fnc->addInput2('button','btnexport',$btnexport,$arr_attr_btnexport,$list_form,'Xuất Excel'); 
	}

//	if ($seed->ACL_Page(2,'List')){	
//		$arr_attr_btndelete = array('style'=>'','onclick'=>'sbm_form(3)');
//		$inp_btndelete = $fnc->addInput2('button','btndelete',$btndelete,$arr_attr_btndelete,$list_form,'Xóa'); 
	//}

	/*----------------------*/
	$list_form->assign('tabs'	,  	$seed->set_tabs());
	/*----------------------*/	
    $list_form->assign('PCsTotal',$seed->TotalRecord);
	$list_form->assign('MODULE'	,  	$seed->object_name);
	$list_form->assign('PN_Error',	$PN_Error);
	$list_form->assign('P_INFO',	$P_INFO);
	$list_form->assign('gridview'	,  	$gridview);
	$list_form->assign('title'	,  	$title);
	$list_form->assign('page_name'	,  	$sugar_config['submenu_name'][$seed->object_name]);

	$list_form->parse('main');
	$list_form->out('main');
	
	ob_end_flush();
} else {
	ACLController::displayNoAccess();
	sugar_die('');
}

class ZT2Remit_Ext  extends ZT2Remit
{
 
	//======================//
	function _AddPageHeader(){
		$_PageHeader=' <br>';
		/*if ($this->ACL_Access('Create','ePMTT')){		
			$_PageHeader=' <br><input type=button value="Thêm mới bạn bè" onclick="user_add()"> <br> <br>'; 
		}*/
		return 	$_PageHeader;	
	}



	function setHeader(){		

		if ($_POST['mode']=='EXPORT' || !$this->ACL_Page(2,'List')){
			$ArrHeader = array(//'STT'						
			'Ngày đăng ký'
			,'Tài khoản CSM cũ'
			
			,'Tài khoản đăng ký'
			,'Tên phòng máy'				
			,'Tên chủ Pm'
			,'Địa chỉ'
			,'Số điện thoại'
            ,'Email'
            ,'CMND'	
			);
		}
		else{
			$ArrHeader = array(//'<input type=checkbox id=check_all name=check_all>'						
			'Ngày đăng ký'
			,'Tài khoản CSM cũ'			
			,'Tài khoản đăng ký'
			,'Tên phòng máy'				
			,'Tên chủ Pm'
			,'Địa chỉ'
			,'Số điện thoại'
            ,'Email'
            ,'CMND'	
			);
			
		}
		$SortHeader = array(0,1,1,1,1,0,0,0);
		//$SortImage[$_POST['_SortOrderBy']]='css_right ui-icon ui-icon-carat-2-n-s';
		if ($_POST['_OrderDirection']=='desc'){
			$SortImage[$_POST['_SortOrderBy']]='css_right ui-icon ui-icon-triangle-1-s';
		}else if ($_POST['_OrderDirection']=='asc'){
			$SortImage[$_POST['_SortOrderBy']]='css_right ui-icon ui-icon-triangle-1-n';
		}
		
		
		$_Header='';
		$_Header.='<div class="hastable"><div id="aj_result"><table   width="100%"  cellspacing="0"  cellpadding="0" border=0>';
		$_Header.='<thead><tr>';
		
		for ($j=0;$j<count($ArrHeader);$j++)
		{
		
			if ($SortHeader[$j])
			{
				if ($SortImage[$j]==''){$SortImage[$j]='css_right ui-icon ui-icon-carat-2-n-s';}
				
				$_Header.='<th class="ui-state-default t_cap" valign=top>
				<a href=javascript:fnOrder('.$j.') >'.$ArrHeader[$j].'
					<span class="'.$SortImage[$j].'"></span>
				</a></th>';
			}
			else
				$_Header.='<th class="ui-state-default t_cap">'.$ArrHeader[$j].'</th>';
		}
		$_Header.='</tr></thead>';
		return $_Header;
	}
    
    //function setList($fnc,$_Where,$_vl_from_date,$list_form){
    function setList($fnc,$_Where,$_vl_from_date,$_vl_to_date,$locationId,$_pst_statusId,$list_form){	
		$result = NULL;	
		$PageSize=10;		
		$this->PageIndex = isset($_POST["page"]) ? $_POST["page"] : 1;		
		if ($_POST['ddlPageSize']!=''){$PageSize=$_POST['ddlPageSize'];}
		$this->PageSize = $PageSize;
		$_FlgExport=false;
		if($_POST['mode']=='EXPORT'){$PageSize=0;$_FlgExport=true;}

		$_Table = '';
		if ($_FlgExport)
		{	$_Field = array('configName','gamecode','from_date','to_date');	
		}else{
			$_Field = array('configName','gamecode','from_date','to_date');	
		}
		
		$_strField = implode(',', $_Field);
		if ($filter!='')	
		{
			$filter_arr = explode('|',$filter);
		}
			
	
		// ===== order =============/
		$_SortOrderBy=$_POST["_SortOrderBy"];
		$_OrderDirection=$_POST["_OrderDirection"];
		
		if (trim($_SortOrderBy)=='' || $_FlgExport)
		{
			$_OrderBy = 'regDate';
			$_OrderDirection = 'desc';	
		}
		else
		{
			$_OrderBy = $_Field[$_SortOrderBy-1];			
		}
		// ===== order =============/
		
	//	$_Where.='';
	//	if (trim($_vl_from_date)!=""){
	//		$_Where.=" and datediff(d,from_date,''".$this->anti($fnc->vndate2date($_vl_from_date),4)."'')=0 ";		
		//}
        
        // m
        
        //$_Where.=' and t1.statusId in (0,1,-13) ';
        
		if ($locationId!=''){
				//$_Where.=" and (t1.locationId in (".$locationId.")) ";
                $_Where.=" and (CityId in (".$locationId.")) ";
		}
        
        //echo 'code: '. $_Where;
        
		if ($_pst_statusId!=''){
			$_Where.=" and (DistrictId in (".$this->anti($_pst_statusId,5,'123456789-').")) ";
		
		}
        
		if (trim($_vl_from_date)!="")
        {

			$_vl_from_date = $this->anti($fnc->vndate2date($_vl_from_date),4) ;
			if ($_vl_to_date=='')
            {
				$_vl_to_date = $_vl_from_date;
			}
			$_vl_to_date = $this->anti($fnc->vndate2date($_vl_to_date),4) ;

           $_Where.=" and regDate between ''".$_vl_from_date."'' and ''".$_vl_to_date."''";
            			
           /* 
            	$_Where.=" and (
						  
							datediff(d,''".$_vl_from_date."'',create_date)>=0 
							and datediff(d,''".$_vl_to_date."'',create_date)<=0   			
						   
					   )
			";*/
            

		}
        
       // echo 'code: '. $_Where;

        // end m

		try
		{	

	
			$_dblist='';			
			$i=0;
			
			
			if ($_POST['mode_inpvl']=='EXPORT')			
				$sSQL="usp_ZT2_Remit_be_GRLV_Members_List 1,0,' and 1=1 $_Where ','".$_OrderBy."','".$_OrderDirection."','*'";			
			else
				$sSQL="usp_ZT2_Remit_be_GRLV_Members_List ".$this->PageIndex.",".$PageSize.",' and 1=1 $_Where  ','".$_OrderBy."','".$_OrderDirection."','*'";			
			////
          // echo $sSQL;
            
			$this->ws_debug($sSQL);
				
				$result = $this->db->query($sSQL, true, "Query failed");					
				
				
			
				
				while ($aR = $this->db->fetchByAssoc($result))
				{
					
					if ($i==0){
						$this->TotalRecord = $fnc->isNull($aR['TotalRecord'],0);						
						$this->TotalPage = intval($this->TotalRecord/$PageSize + ($this->TotalRecord%$PageSize > 0?1:0));					
										
					}					
				
					$STT = ($i+($this->PageIndex-1)*$PageSize)+1;
                    //m
                   // var_dump($aR);
                   // die();
                    
                   	$_regDate = $aR['regDate']; 
					$_oldZingId = $aR['oldZingId']; 
					$_newZingId = $aR['newZingId'];                    		
                    $_FullName = $aR['FullName']; 
					$_GameRoomName = $aR['GameRoomName']; 
                    $city = $aR['CityId'];                   
					$_Address = $aR['Address']; 
					$_Phone = $aR['Phone']; 
					$_Email = $aR['Email']; 
					$_CMND = $aR['CMND'];
                    //end m                    	
					
					$_dblist.='<tr>';
							
							if ($_POST['mode']=='EXPORT' || !$this->ACL_Page(2,'List')){
								$_dblist.='<td  style="text-align:center" width=50>'.$STT.'</td>';							
							}else{

								$arr_attr_keyword = array('style'=>'');
							//	$inp_del = '<input type=checkbox value="'.$Id.'" name="chk[]" id="chk_'.$Id.'">';
								//$_dblist.='<td  style="text-align:center" width=50>'.$inp_del.'</td>';							
							}
                            
							//$_dblist.='<td  style="text-align:left">'.$_regDate.'</td>';	
                            $_dblist.='<td  style="text-align:center">'.$fnc->date2vndate($_regDate,false).'</td>';	
							
						//	$_dblist.='<td  style="text-align:left"><a href="javascript:fnc_get_config('.$Id.',\''.$fnc->md5sum($Id.'@cfg').'\')">'.$_vconfigName.'</a></td>';	
							$_dblist.='<td  style="text-align:left">'.$_oldZingId.'</td>';
                            $_dblist.='<td  style="text-align:left">'.$_newZingId.'</td>';
                            $_dblist.='<td  style="text-align:left">'.$_FullName.'</td>';
                            $_dblist.='<td  style="text-align:left">'.$_GameRoomName.'</td>';
                            $_dblist.='<td  style="text-align:left">'.$_Address.'</td>';
                            $_dblist.='<td  style="text-align:left">'.$_Phone.'</td>';
                            $_dblist.='<td  style="text-align:left">'.$_Email.'</td>';
                            $_dblist.='<td  style="text-align:left">'.$_CMND.'</td>';
                             
						//	$_dblist.='<td  style="text-align:center">'.$fnc->date2vndate($_veffect_fromdate,false).' - '.$fnc->date2vndate($_veffect_todate,false).'</td>';	
							//$_dblist.='<td  style="text-align:center">'.$fnc->date2vndate($_vfrom_date,false).' - '.$fnc->date2vndate($_vto_date,false).'</td>';							
							//$_dblist.='<td  style="text-align:center" id="codedf_'.$Id.'">'.$_vqty_code_default.'</td>';	
						//	$_dblist.='<td  style="text-align:center">'.$_vmaxUser.'</td>';	
							//$_dblist.='<td  style="text-align:center">'.$_vstatus_code.'</td>';	

																			
							
																												
					$_dblist.='</tr>';			
				
					
					$i++;
				}				
			
			
			if ($i==0){
					if ($this->TotalRecord==0)
						{
							$_dblist.='<tr><td colspan=100>Không tìm thấy thông tin</td></tr>';	
						}	
			}else{	}
			
				
		}
		catch (PDOException $ex)
		{}			
		
		$list[0] = $_dblist;

			
		return $list;			
		
	}	

	/*function pmtt_config_delete($statId, $epmttId_List){
		$sSQL="exec usp_pmtt_be_config_delete_v1 $statId, '".$epmttId_List."','".$_SESSION['ws_login_user']."'";	
		$this->db->query($sSQL, true, "Query failed");
	}
*/
/*
	function pmtt_config_add($fnc,$add_config_name,$add_gamecode_list,$add_from_date,$add_to_date,$add_status,$add_user,$add_level,$_pst_effect_fromdate,$_pst_effect_todate,$mode_pm,$mode_gamer,$mode_register,$_pst_kpi_pm,$_pst_kpi_gamer,$_pst_kpi_revenue,$_pst_kpi_playingtime)
	{
		if ($add_user=='')
			$add_user=200;
		if ($add_level=='')
			$add_level=0;


		if ($add_config_name!='' && $add_gamecode_list!='' && $add_from_date!='' && $add_to_date!=''  && $_pst_effect_fromdate!='' && $_pst_effect_todate!='' && $_pst_kpi_pm!='' && $_pst_kpi_gamer!='' && $_pst_kpi_revenue!='' && $_pst_kpi_playingtime!=''  )
		{
			$add_from_date = $fnc->vndate2date($add_from_date);
			$add_to_date = $fnc->vndate2date($add_to_date);
			$_pst_effect_fromdate = $fnc->vndate2date($_pst_effect_fromdate);
			$_pst_effect_todate = $fnc->vndate2date($_pst_effect_todate);



			$sSQL="exec usp_pmtt_be_config_add_v3 0,'".$add_config_name."','".$add_gamecode_list."','".$add_from_date."','".$add_to_date."',0,'".$_SESSION['ws_login_user']."',$add_user,$add_level,'".$_pst_effect_fromdate."','".$_pst_effect_todate."',$mode_pm,$mode_gamer,$mode_register,$_pst_kpi_pm,$_pst_kpi_gamer,$_pst_kpi_revenue,$_pst_kpi_playingtime";	
			//echo $sSQL;
			$result = $this->db->query($sSQL, true, "Query failed");	
			$aR = $this->db->fetchByAssoc($result);
			var_dump($aR);
			return $aR['result'];
		}
		return -1;
	
	}
    */
	function fnc_get_locationId($Id){
			$sSQL="exec usp_vng_location 2,".$Id." ,0,0 ";
			$result = $this->db->query($sSQL, true, "Query failed");	
			$aR = $this->db->fetchByAssoc($result);
			return '0'.$aR['id'];	
	}





							  
								  




}


?>